import { Message } from '@arco-design/web-vue'
import { createMenuApi, modifyMenuApi } from '@/apis/codePulse/menu'
import { FormRef, emit } from './AddMenuModal.vue'

export const save = async () => {
  try {
    const info = await FormRef.value?.validate()
    if (info) return false
    const meta = JSON.stringify({
      hidden: info.hidden,
      affix: info.affix,
      breadcrumb: info.breadcrumb,
      showInTabs: info.showInTabs,
      activeMenu: info.activeMenu,
      alwaysShow: info.alwaysShow
    })
    info.meta = meta
    if (info.id) {
      await modifyMenuApi(info)
    } else {
      await createMenuApi(info)
    }

    if (res.data) {
      Message.success('模拟保存成功')
      emit('save-success')
      return true
    } else {
      return false
    }
  } catch (error) {
    return false
  }
}
